#!/bin/sh

# 启动终端
riverctl map normal Super Return spawn foot
riverctl map normal Super Q spawn foot

# 通过终端从输入法获取字符串
riverctl map normal Super A spawn "foot --app-id get-string vim -u ~/.vim/get-string.vimrc && wl-past --no-newline | wtype -"

# 应用启动噐
riverctl map normal Super D spawn "rofi -show drun"

# 关闭窗口
riverctl map normal Super C close

# 文件管理器
riverctl map normal Super E spawn "foot ranger"

# 退出 river 会话
riverctl map normal Super M exit

# 窗口焦点移动
riverctl map normal Super J focus-view next
riverctl map normal Super K focus-view previous

# 窗口交换
riverctl map normal Super+Shift J swap next
riverctl map normal Super+Shift K swap previous

# 显示器焦点切换
riverctl map normal Super Period focus-output next
riverctl map normal Super Comma focus-output previous

# 将当前窗口发送到其他显示器
riverctl map normal Super+Shift Period send-to-output next
riverctl map normal Super+Shift Comma send-to-output previous

# 聚焦当前窗口
riverctl map normal Super+Shift Return zoom

riverctl map normal Super H send-layout-cmd rivertile "main-ratio -0.05"
riverctl map normal Super L send-layout-cmd rivertile "main-ratio +0.05"

riverctl map normal Super+Shift H send-layout-cmd rivertile "main-count +1"
riverctl map normal Super+Shift L send-layout-cmd rivertile "main-count -1"

riverctl map normal Super+Alt H move left 100
riverctl map normal Super+Alt J move down 100
riverctl map normal Super+Alt K move up 100
riverctl map normal Super+Alt L move right 100

riverctl map normal Super+Alt+Control H snap left
riverctl map normal Super+Alt+Control J snap down
riverctl map normal Super+Alt+Control K snap up
riverctl map normal Super+Alt+Control L snap right

# 调整窗口尺寸
riverctl map normal Super+Alt+Shift H resize horizontal -100
riverctl map normal Super+Alt+Shift J resize vertical 100
riverctl map normal Super+Alt+Shift K resize vertical -100
riverctl map normal Super+Alt+Shift L resize horizontal 100

riverctl map-pointer normal Super BTN_LEFT move-view

riverctl map-pointer normal Super BTN_RIGHT resize-view

riverctl map-pointer normal Super BTN_MIDDLE toggle-float

for i in $(seq 1 9)
do
    tags=$((1 << ($i - 1)))
    riverctl map normal Super $i set-focused-tags $tags
    riverctl map normal Super+Shift $i set-view-tags $tags
    riverctl map normal Super+Control $i toggle-focused-tags $tags
    riverctl map normal Super+Shift+Control $i toggle-view-tags $tags
done

# Super+0 展示所以 tags 上的窗口
all_tags=$(((1 << 32) - 1))
riverctl map normal Super 0 set-focused-tags $all_tags
riverctl map normal Super+Shift 0 set-view-tags $all_tags

# 切换浮动
riverctl map normal Super V toggle-float

# 浮动窗口
riverctl rule-add -app-id 'get-string' float

# 窗口全屏
riverctl map normal Super F toggle-fullscreen

riverctl map normal Super Up    send-layout-cmd rivertile "main-location top"
riverctl map normal Super Right send-layout-cmd rivertile "main-location right"
riverctl map normal Super Down  send-layout-cmd rivertile "main-location bottom"
riverctl map normal Super Left  send-layout-cmd rivertile "main-location left"

riverctl declare-mode passthrough
riverctl map normal Super F11 enter-mode passthrough
riverctl map passthrough Super F11 enter-mode normal

# 背景和边框颜色
riverctl background-color 0x002b36
riverctl border-color-focused 0x93a1a1
riverctl border-color-unfocused 0x586e75

# 按键重复速度
riverctl set-repeat 50 300

riverctl rule-add -app-id 'float*' -title 'foo' float
riverctl rule-add -app-id "bar" csd

# 默认的布局生成噐
riverctl default-layout rivertile
rivertile -view-padding 3 -outer-padding 3 &

# 自启动进程
riverctl spawn "fcitx5 --replace -d"
riverctl spawn "waybar -c ~/.config/waybar/config-river"
riverctl spawn "swaybg -i ~/.config/wallpapers/wallpaper.png -m fill"
riverctl spawn "mako"

# 环境变量
systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP
dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=river

# 显示噐示例配置
#riverctl spawn "wlr-randr --output eDP-1 --scale 2.0 --pos 0,0"
#riverctl spawn "wlr-randr --output DP-2 --scale 1.0 --pos -1920,-150"
#
# 锁定桌面
# river 没有自己的空闲管理器，因此使用 hyprland 的空闲管理器，使用 wlopm 熄屏
#riverctl map normal Super+Shift Q spawn "hyprlock"
#riverctl spawn "hypridle -c ~/.config/hypridle/hypridle-river.conf"
# 对于 OpenGL 版本较低的设备无法使用 hyprlock，使用 swayidle + swaylock 替代
#riverctl map normal Super+Shift Q spawn "swaylock  --screenshots  --clock --indicator  --indicator-radius 100  --indicator-thickness 7  --effect-blur 7x5  --effect-vignette 0.5:0.5  --ring-color bb00cc  --key-hl-color 880033  --line-color 00000000  --inside-color 00000088  --separator-color 00000000  --grace 2  --fade-in 0.2"
#riverctl spawn "swayidle -w timeout 1800 'swaylock  --screenshots  --clock --indicator  --indicator-radius 100  --indicator-thickness 7  --effect-blur 7x5  --effect-vignette 0.5:0.5  --ring-color bb00cc  --key-hl-color 880033  --line-color 00000000  --inside-color 00000088  --separator-color 00000000  --grace 2  --fade-in 0.2' timeout 2100 'wlopm --off eDP-1' resume 'wlopm --on eDP-1'"
#
# 触控板示例配置
#riverctl input "pointer-1739-32552-MSFT0001:02_06CB:7F28_Touchpad" tap enabled
#riverctl input "pointer-1739-32552-MSFT0001:02_06CB:7F28_Touchpad" natural-scroll enabled

# 用户自定义配置, 请自行创建 custom.sh 文件，然后解除注释
#source ~/.config/river/custom.sh

# vim: set ft=sh
